home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacWorld 1997 September
/
Macworld (1997-09).dmg
/
Serious Software
/
Cherwell Scientific Demos
/
pro Fit
/
pro Fit 5.0 demo (fpu).sea
/
pro Fit 5.0 demo (fpu)
/
Functions & Programs
/
Polar plot
< prev
next >
Wrap
Text File
|
1996-04-20
|
5KB
|
197 lines
{ This file defines the program PolarPlot:
- creates a graph if necessary
- a polar grid in it if desired
- plots a data set in the polar plot
To use this program:
1. Choose "Add to Menu" from the "Misc" menu to add them
to your menus.
2. Open a data window and enter your data points (phi[deg], r)
3. Choose "PolarPlot" from the "Misc" menu to plot them.
}
program PolarPlot;
var
phi, r, rmax, radmax, ncirc, degrad, windID, dataID, curGraph;
x, y; { results of Translate }
left, top, right, bottom, mean;
phiColumn, rColumn, i;
plotCG, plotGrid, drawLabels;
procedure Initialize;
{ set defaults }
begin
plotCG := 0;
plotGrid := 1;
drawLabels := 1;
phiColumn := 1;
rColumn := 2;
radmax := 1;
ncirc := 5;
degrad := 5;
end;
procedure Translate(r, p);
{ translates the point at r,pp (=radius, phi in degree) to a coordinate }
{ in the current graph. The result is stored in the variables x, y }
var phiRad;
begin
phiRad := p * (π/180);
x := cos(phiRad) * r;
y := sin(phiRad) * r;
end;
procedure PreparePolarPlot;
var cenH, cenV;
begin
windID := FrontmostWindow(drawingType);
if windID = 0 then
NewWindow(drawingType)
else
BringWindowToFront(windID); { it could contain the current graph }
rmax := radmax * 1.1;
SetLineColor(0,0,0);
curGraph := GetCurrentGraph;
if (not plotCG) or (curGraph = 0) then
begin
DisableDrawingUpdates; { when creating the graph and the grid we want less update }
GroupBegin;
{ create the graph }
CreateNewGraph(-rmax,rmax,-rmax,rmax,0,0);
{ draw and set the axes, ticks and labels (radial) }
SetCurrentAxis(xAxis,1);
SetAxisPosition(xAxis,-rmax);
MakeTicks(xAxis,0,radmax,ncirc-1);
if drawLabels then
begin
MakeTicks(xAxis,0,radmax,ncirc-1);
SetAxisAttributes(xAxis,drawAxisLine+drawTicks+drawMajorTickLabels+plusSideTicks)
end
else
SetAxisAttributes(xAxis,drawAxisLine);
SetCurrentAxis(xAxis,2);
SetAxisPosition(xAxis,rmax);
SetAxisAttributes(xAxis,drawAxisLine);
SetCurrentAxis(yAxis,1);
SetAxisPosition(yAxis,-rmax);
SetAxisAttributes(yAxis,drawAxisLine);
SetCurrentAxis(yAxis,2);
SetAxisPosition(yAxis,rmax);
SetAxisAttributes(yAxis,drawAxisLine);
{ set the graphs size }
GetGraphFrame(left,top,right,bottom);
mean := (left + top + right + bottom) / 4;
if mean < 150 then
mean := 150;
SetGraphFrame(left,top,left + mean,top + mean); { make it a square }
{ draw the angles labels and an arc with arrow }
if drawLabels then
begin
cenH := left + mean * 0.5;
cenV := top + mean * 0.5;
SetArrowStyle(2,1,16);
OpenPoly(1,false);
phi := π/18;
MoveTo(cenH + mean * 0.6 * cos(phi), cenV - mean * 0.6 * sin(phi));
phi := phi + π/18;
repeat
LineTo(cenH + mean * 0.6 * cos(phi), cenV - mean * 0.6 * sin(phi));
phi := phi + π/18;
until phi > π/2 - π/18;
ClosePoly;
SetArrowStyle(2,0,16);
MoveTo(cenH + mean * 0.6, cenV);
DrawText('0°',0,true);
MoveTo(cenH, cenV - mean * 0.6);
DrawText('90°',0,true);
end;
GroupEnd;
end;
if plotGrid then
begin
SetLineStyle(1,1);
SetLineColor(65000, 0, 65000); { magenta }
OpenCurve('grid radial');
if degrad <= 4 then
r := 15 * degrad
else if degrad <= 6 then
r := 30 * (degrad - 2)
else
r := 180 * (degrad - 6);
r := r * π / 180;
phi := 0;
repeat
MoveTo(0, 0); LineTo(cos(phi) * rmax, sin(phi) * rmax);
phi := phi + r;
until phi >= 2 * π;
CloseCurve;
SetLineStyle(0.5,1);
SetLineColor(0, 0, 65000); { blue }
OpenCurve('grid circular');
r := radmax / ncirc;
repeat
MoveTo(r, 0);
phi := 6;
repeat
Translate(r, phi);
LineTo(x, y);
phi := phi + 6;
until phi > 360;
r := r + radmax / ncirc;
until r * 0.99 > radmax;
CloseCurve;
end;
end;
begin
curGraph := GetCurrentGraph;
if curGraph = 0 then
begin
plotCG := 0;
plotGrid := 1;
drawLabels := 1;
end
else
begin
plotCG := 1;
plotGrid := 0;
drawLabels := 0;
end;
SetBoxTitle('Polar Plot Preparation');
Input('$XPlot into current graph', plotCG,
'$XPlot polar grid', plotGrid,
'$XDraw labels', drawLabels,
'Maximum radius', radmax,
'$P1;2;3;4;5;6;7;8;9;10$# circular gridlines', ncirc,
'$P15;30;45;60;90;120;180;360$Radial gridlines at', degrad);
PreparePolarPlot;
SetBoxTitle('Polar Plot');
Input('$WData window', dataID, '$CAngle [degree]', phiColumn, '$CRadius', rColumn);
SetDataPointStyle(15,6,1);
SetLineColor(65535, 0, 0); { red }
OpenDataSet(false,false,'data');
for i:=1 to nrRows do
if (dataOK(i, phiColumn) and dataOK(i,rColumn)) then { if both fields hold a value }
begin
Translate(data[i, rColumn], data[i, phiColumn]);
AddDataPoint(x,y,0,0,0,0);
end;
end;